﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;

namespace TestLog.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }

        /// <summary>
        /// 测试日志
        /// </summary>
        /// <param name="isLog">启用日志</param>
        /// <returns></returns>
        [HttpGet]
        [DisplayName("测试日志")]
        [Route("TestLog")]
        public string TestLog()
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            int n = 5;
            int ii = 0;

            for (var i = 0; i < n; i++)
            {
                ii += 3;
                //_logger.LogInformation("Microsoft.Extensions.Logging测试日志{0}:{1}", n, ii);

                Log.Information("SeriLog测试日志{0}:{1}", n, ii);
            }

            watch.Stop();
            Log.Information($"【调用耗时】:{watch.ElapsedMilliseconds}毫秒");

            Task.Delay(1000).Wait();
            return "OK";
        }




    }
}
